import { Component, Input, OnInit, } from '@angular/core';
import { TIM } from '../shared.data';

@Component({
  selector: 'im-avatar',
  templateUrl: './avatar.component.html',
  styleUrls: ['./avatar.component.less'],
})
export class AvatarComponent implements OnInit {
  @Input() shape: 'circle' | 'square' = 'circle';
  @Input() size: 'large' | 'small' | 'default' | number = 'large';
  @Input() type: string = 'C2C';
  @Input() title: string;
  @Input() set src(value: string) {
    this._src = value;
    if (/^(https:|http:|\/\/)/.test(value)) {
      this.avatarSrc = value;
    } else {
      this.avatarSrc = this.getDefaultAvatar();
    }
  };
  get src() {
    return this._src;
  }

  private _src: string;

  avatarSrc: string;

  constructor() { }

  ngOnInit(): void {
  }


  getDefaultAvatar() {
    switch (this.type) {
      case 'C2C':
        // 个人头像
        return 'https://imgcache.qq.com/open/qcloud/video/act/webim-avatar/avatar-2.png';
      case 'GROUP':
        // 群默认头像
        return 'https://imgcache.qq.com/open/qcloud/video/act/webim-avatar/avatar-3.png';
      case TIM.TYPES.CONV_SYSTEM:
        return '';
      default:
        // 默认头像
        return 'https://imgcache.qq.com/open/qcloud/video/act/webim-avatar/avatar-1.png';
    }
  }

}
